﻿#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
import json

# cron:12 6,18 * * *

url = 'http://www.biiyy.com/member.php?mod=logging&action=login&loginsubmit=yes&handlekey=login&loginhash=Luql4&inajax=1'
headers = {'Host': 'www.biiyy.com', 'Connection': 'keep-alive', 'Content-Length': '133', 'Cache-Control': 'max-age=0', 'Upgrade-Insecure-Requests': '1', 'Origin': 'http://www.biiyy.com', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Referer': 'http://www.biiyy.com/', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,zh;q=0.9'}
cookies = {'fZnn_2132_saltkey': 'K03ffBYO', 'fZnn_2132_lastvisit': '1662688969', 'fZnn_2132_sid': 'Vu97t7', 'fZnn_2132_onlineusernum': '545', '_ga_KYC5Y1Q7PB': 'GS1.1.1662692568.1.0.1662692568.0.0.0', '_ga': 'GA1.1.3741669.1662692569', '__gads': 'ID', '__gpi': 'UID', 'fZnn_2132_sendmail': '1', '__tins__20697343': '%7B%22sid%22%3A%201662692571300%2C%20%22vd%22%3A%201%2C%20%22expires%22%3A%201662694371300%7D', '__51cke__': '', '__51laig__': '1', 'Hm_lvt_02f6cc3a18049348b7027863415af639': '1662692572', 'Hm_lpvt_02f6cc3a18049348b7027863415af639': '1662692572', 'fZnn_2132_lastact': '1662692576%09member.php%09logging'}
data = {'formhash': '0dca51c8', 'referer': 'http%3A%2F%2Fwww.biiyy.com%2F', 'loginfield': 'username', 'username': 'linxiang', 'password': 'lin123456', 'questionid': '0', 'answer': ''}

html = requests.post(url, headers=headers, verify=False, cookies=cookies, data=data)
print(len(html.text))
print(html.text) 
print(html.headers)
tui = html.text


urlwx = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken'
corpid = 'wwbe7a837b20998a38'
corpsecret = 'hQdFy9ng0s7Gs5Mq4n4TtPyoDVBqWCakZgvXXZybL4M'

# 获取token时，携带企业id和secret(注册企业号时，后台可查)
values = {'corpid': corpid, 'corpsecret': corpsecret}
reqwx = requests.get(url=urlwx, params=values)
datawx = json.loads(reqwx.text)
access_token = datawx["access_token"]
print(access_token)
urlwx2 = f'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={access_token}'
# 图文
tuwen = {
    "touser": "@all",
    "toparty": "",
    "totag": "",
    "msgtype": "mpnews",
    "agentid": 1000008,
    "mpnews": {
        "articles": [
            {
                "title": "师哈哈登录",
                "thumb_media_id": "20inlgKNG8LegISqzm48t-_eiAH2vRCjpk9rcBPAPOMzWqOQYcw4GyZCY5uqnIoci",
                "author": "帅气的林老师",
                "content_source_url": "",
                "content": tui,
                "digest": tui
            }
        ]
    },
    "safe": 0,
    "enable_id_trans": 0,
    "enable_duplicate_check": 0,
    "duplicate_check_interval": 1800
}
# 文本
wenben = {
    "touser": "@all",
    "toparty": "",
    "totag": "",
    "msgtype": "text",
    "agentid": 1000008,
    "text": {"content": "你的快递已到，请携带工卡前往邮件中心领取。\n出发前可查看<a href=\"http://work.weixin.qq.com\">邮件中心视频实况</a>，聪明避开排队。"},
    "safe": 0,
    "enable_id_trans": 0,
    "enable_duplicate_check": 0,
    "duplicate_check_interval": 1800
}
# 文本卡片
wenbenkapian = {
    "touser": "@all",
    "toparty": "",
    "totag": "",
    "msgtype": "textcard",
    "agentid": 1000008,
    "textcard": {
        "title": "领奖通知",
        "description": tui,
        "url": " ",
        "btntxt": "更多"
    },
    "enable_id_trans": 0,
    "enable_duplicate_check": 0,
    "duplicate_check_interval": 1800
}
# wxtui = requests.post(url=urlwx2, json=tuwen)
kapian = requests.post(url=urlwx2, json=tuwen)
# print(kapian.text)

